/**
 * @author 小泽玛丽罗

 * @version 2014/10/26 pm6:36
 * 
 */



/**
 * 绑定点赞事件
 */
function likeWeibo(){
	var userId=$(this);
	var row=$(this).attr("row");
	if(userId==0&&userId!=null){
		toast.error("请先登录再点赞，即将为您跳转到登录页", "温馨提示");
		 setTimeout(function () {
             location.href = "http://localhost:8080/JavaTox/home/login.jsp";
         }, 1500);
	}else{
		var weiboId=$(this).prop("row");
		$.ajax({
			type:"post",
			url:likeWeibo.action,
			data:{weibo_id:weiboId},
			success:function(data){
				var json=eval("("+data+")");
				if(json["success"]){
					toast.success("点赞成功", "温馨提示");
					var ico=$(this).find("#ico_like");
					ico.removeClass();
					ico.addClass('support_like');
				}else{
					toast.error(json["msg"], "温馨提示");
				}
			},
			error:function(){
				toast.error("不好意思点赞失败", "温馨提示");
			}
			
			
		});
	}
	
}

function validateForm_reg() {
	var username = $("#username").val();
	var password = $("#password").val();
	var mobile = $("#mobile").val();
	var email = $("#email").val();
	var uName_reg_len = /.{4,16}/;
	var uName_reg_comp = /[^0-9a-zA-Z_]/;
	var pwd_reg = /.{6,30}/;
	var email_reg = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
	var phone_reg = /^(13[0-9]{9})|(15[0-9]{9})|(17[0-9]{9}|(18[0-9]{9}))$/;
	if (username == "") {
		toast.error("请填写用户名", "温馨提示");
		
		return false;
	}
	if (!uName_reg_len.test(username)) {
		toast.error("用户名长度在4到16个字符", "温馨提示");
		
		return false;
	}
	if (uName_reg_comp.test(username)) {
		toast.error("用户名只允许字母和数字和下划线", "温馨提示");
		
		return false;
	}
	if (!pwd_reg.test(password)) {
		toast.error("密码的长度必须在6~30个字符之间", "温馨提示");
		
		return false;
	}
	if (!email_reg.test(email)) {
		toast.error("请填写正确的邮箱格式ʽ", "温馨提示");
		
		return false;
	}
	if (!phone_reg.test(mobile)) {
		toast.error("请填写正确的手机号码", "温馨提示");
		
		return false;
	}
	return true;
}

function validateForm_login() {
	var username=$("#username").val().trim();
	var password=$("#password").val().trim();
	var securityCode=$("#security").val().trim();
	var uName_reg_len = /.{4,16}/;
	var uName_reg_comp = /[^0-9a-zA-Z_]/;
	var pwd_reg = /.{6,30}/;
	if (username == "") {
		toast.error("请填写用户名", '温馨提示');
		return false;
	}
	if (!uName_reg_len.test(username)) {
		toast.error("用户名长度在4到16个字符", "温馨提示");
		
		return false;
	}
	if (uName_reg_comp.test(username)) {
		toast.error("用户名只允许字母和数字和下划线", "温馨提示");
		
		return false;
	}
	if (!pwd_reg.test(password)) {
		toast.error("密码的长度必须在6~30个字符之间", "温馨提示");
		
		return false;
	}
	return true;
}

var toast = {
	    /**
	     * 成功提示
	     * @param text 内容
	     * @param title 标题
	     */
	    success: function (text, title) {
	        toastr.options = {
	            "closeButton": true,
	            "debug": false,
	            "positionClass": "toast-center",
	            "onclick": null,
	            "showDuration": "1000",
	            "hideDuration": "1000",
	            "timeOut": "5000",
	            "extendedTimeOut": "1000",
	            "showEasing": "swing",
	            "hideEasing": "linear",
	            "showMethod": "fadeIn",
	            "hideMethod": "fadeOut"
	        };
	        toastr.success(text, title);
	    },
	    /**
	     * 失败提示
	     * @param text 内容
	     * @param title 标题
	     */
	    error: function (text, title) {
	        toastr.options = {
	            "closeButton": true,
	            "debug": false,
	            "positionClass": "toast-center",
	            "onclick": null,
	            "showDuration": "1000",
	            "hideDuration": "1000",
	            "timeOut": "5000",
	            "extendedTimeOut": "1000",
	            "showEasing": "swing",
	            "hideEasing": "linear",
	            "showMethod": "fadeIn",
	            "hideMethod": "fadeOut"
	        };
	        toastr.error(text, title);
	    },
	    /**
	     * 信息提示
	     * @param text 内容
	     * @param title 标题
	     */
	    info: function (text, title) {
	        toastr.options = {
	            "closeButton": false,
	            "debug": false,
	            "positionClass": "toast-center",
	            "onclick": null,
	            "showDuration": "1000",
	            "hideDuration": "1000",
	            "timeOut": "5000",
	            "extendedTimeOut": "1000",
	            "showEasing": "swing",
	            "hideEasing": "linear",
	            "showMethod": "fadeIn",
	            "hideMethod": "fadeOut"
	        };
	        toastr.info(text, title);
	    },
	    /**
	     * 警告提示
	     * @param text 内容
	     * @param title 标题
	     */
	    warning: function (text, title) {
	        toastr.options = {
	            "closeButton": false,
	            "debug": false,
	            "positionClass": "toast-center",
	            "onclick": null,
	            "showDuration": "1000",
	            "hideDuration": "1000",
	            "timeOut": "5000",
	            "extendedTimeOut": "1000",
	            "showEasing": "swing",
	            "hideEasing": "linear",
	            "showMethod": "fadeIn",
	            "hideMethod": "fadeOut"
	        };
	        toastr.warning(text, title);
	    }
	};